# -*- coding: utf-8 -*-
# @Time : 2021/9/10 10:40
# @Author : 阿怪
# @Email : scg@gmail.com
# @File : CRM-ST-YX-046.py
# @Project : crm自动化测试项目实战
'''验证短信模板的批量删除功能—勾选单个删除'''
from selenium import webdriver
from selenium.webdriver.common.by import By
from time import sleep
from selenium.webdriver.common.alert import Alert  # 把弹窗封装成类Alert

driver = webdriver.Chrome()
cookie = {'name': 'PHPSESSID', 'value': '0onrpth7nsd6mbi1hfgi99o2b1'}  # 获取到cookid
driver.get('http://192.168.1.140/')  # 访问服务器
driver.add_cookie(cookie)
driver.get('http://192.168.1.140/crm3/index.php?m=sms&a=index')
#进入短信模板设置首页

add_message_locator = (By.ID,'add')  #添加短信模板定位器
driver.find_element(*add_message_locator).click()
#进入模板编辑界面

sleep(3)
 #先去添加一条短信模板：
add_tittle_locator = (By.CSS_SELECTOR,'input[name="subject"]')
text_locator = (By.ID,'content')
submit_locator = (By.CSS_SELECTOR,'#dialog-add > form > table > tfoot > tr > td > input.btn.btn-primary')
# 1.在标题输入框中输入标题
driver.find_element(*add_tittle_locator).send_keys('生日模板')
# 2.在内容输入框中输入内容
driver.find_element(*text_locator).send_keys('亲爱的客户，生日快乐')
# 3.点击【保存】
driver.find_element(*submit_locator).click()



driver.find_element(By.CSS_SELECTOR, '#form1 > div:nth-child(2) > table > tbody > tr:nth-child(1) > td:nth-child(1) > input').click()  # 点击全首条选中
driver.find_element(By.CSS_SELECTOR,'#btn_delete').click()  # 点击删除
sleep(2)
alert = Alert(driver)
alert.accept()
sleep(2)
driver.quit()